#include <stdio.h>
#include <stdlib.h>
#include <math.h>

using namespace std;

struct t_employee
{
       char name[15];
       char surname[15];
       float salary;
       int id;
};
float avg_salary(int n, t_employee employees[])
{
      float avg_sal=0.00;
      for(int i=0;i<n;i++)
      avg_sal+=employees[i].salary;
      return avg_sal/=n;
}

void sort_by_salary(int n, t_employee employees[])
{
  int i, j;
  t_employee temp;

  for (i = (n - 1); i > 0; i--)
  {
    for (j = 1; j <= i; j++)
    {
      if (employees[j-1].salary < employees[j].salary)
      {
        temp = employees[j-1];
        employees[j-1] = employees[j];
        employees[j] = temp;
      }
    }
  }
}


int main()
{
    const int n=3;
    t_employee employees[n];

    for(int i=0;i<n;i++)
    {
            printf("Podaj dane %i pracownika(ID imie nazwisko pensja)\n",i+1);
            scanf("%i %s %s %f",&employees[i].id,&employees[i].name,&employees[i].surname,&employees[i].salary);
            printf("\n");
    }
    sort_by_salary(n,employees);
    printf("Lista pracownikow:\n");
    printf("ID    imie       nazwisko             pensja\n");
    for(int i=0;i<n;i++)
    {
            printf("%-5i %-15s %-15s %-.2f\n",employees[i].id,employees[i].name,employees[i].surname,employees[i].salary);
    }
    printf("Srednia pensja: %.2f",avg_salary(n,employees));
    getchar();
    getchar();
    return 0;
}
